<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <div>
      <!-- 登录后的上半 -->
    <div class="loginup" v-if="token">
      <!-- 上半图 -->
      <div class="uppic"></div>
      <!-- 上半下白 -->
      <div class="updown">
        <!-- 圆形 -->
        <div class="yuan">
          <!-- 头像 -->
          <div class="avatar"></div>
        </div>
        <!-- 用户名 -->
        <div class="you">{{nickname}}</div>
        <!-- 退出登录 -->
        <button class="outlogin" @click="loginout">退出登录</button>
        <!-- 编辑个人资料 -->
        <div class="usermsg">编辑个人资料</div>
      </div>
    </div>
    <div class="My_title__39w3V" v-else>
      <div class="My_bg__2j-VX">
        <img src="http://liufusong.top:8080/img/profile/bg.png" alt="" />
        <div class="My_info__eOYeg">
          <div class="My_myIcon__3cKIV">
            <img
              src="http://liufusong.top:8080/img/profile/avatar.png"
              alt=""
            />
          </div>
          <div class="My_user__B6O1D">
            <div class="My_name__3U2NB">游客</div>
            <div class="My_edit__3wqlv">
              <van-button type="primary"  to="/login"
                >去登录</van-button
              >
            </div>
          </div>
        </div>
      </div>
    </div>
    <van-grid :column-num="3" :gutter="40" :border="false" class="two">
      <van-grid-item icon="star-o" text="我的收藏"  @click="$router.push('/collect')"/>
      <van-grid-item icon="wap-home-o" text="我的出租"  @click="$router.push('/MyHousingManagement')"/>
      <van-grid-item icon="clock-o" text="看房记录" />
    </van-grid>
    <van-grid :column-num="3" :gutter="40" :border="false" class="two-one">
      <van-grid-item icon="notes-o" text="成为房主" />
      <van-grid-item icon="contact" text="个人资料" />
      <van-grid-item icon="service-o" text="联系我们" />
    </van-grid>
    <div class="three">
      <img src="http://liufusong.top:8080/img/profile/join.png" alt="" />
    </div>
  </div>
</template>

<script>
import { getUserData } from '@/api/article'
import { getToken, delToken } from '@/utils/storage'
export default {
  async created () {
    const res = await getUserData()
    console.log(res)
    this.nickname = res.body.nickname
  },
  data () {
    return {
      active: 0,
      nickname: ''
    }
  },
  methods: {
    loginFn () {
      this.$router.push('/login')
    },
    loginout () {
      delToken()
      this.$router.push('/login')
      this.$toast.success('退出成功')
    }
  },
  computed: {
    token () {
      return getToken()
    }
  }
}
</script>

<style lang="less" scoped>
.My_title__39w3V {
  min-height: 300px;
  position: relative;
  .My_bg__2j-VX {
    img {
      width: 100%;
    }
    .My_info__eOYeg {
      position: absolute;
      background: #fff;
      width: 75%;
      height: 55%;
      bottom: 0;
      left: 50%;
      transform: translateX(-50%);
      box-shadow: 0 0 10px 3px #ddd;
      margin: 50px auto 0;
      padding: 0 20px;
      text-align: center;
      font-size: 13px;
      .My_myIcon__3cKIV {
        position: relative;
        transform: translateY(-50%);
        border-radius: 50%;
        width: 70px;
        height: 70px;
        border: 5px solid #f5f5f5;
        display: inline-block;
        box-shadow: 0 2px 2px #bdbdbd;
        img {
          width: 100%;
          border-radius: 50%;
        }
      }
      .My_user__B6O1D {
        padding-top: 15px;
        .My_name__3U2NB {
          margin-top: -30px;
          margin-bottom: 10px;
        }
        .My_edit__3wqlv {
          color: #999;
          font-size: 12px;
          margin-top: 20px;
        }
      }
    }
  }
}

.two {
  margin-top: 10px;
}
.two-one {
  margin-top: 10px;
}
.three {
  text-align: center;
  margin-top: 10px;
  img {
    width: 94%;
  }
}
.loginup{
  width: 100%;
  height: 51.1vh;
  position: relative;
  margin-bottom: 2vh;
   .uppic{
    width: 100%;
    height: 51.1vh;
    // background-color: saddlebrown;
    position: absolute;
    left: 0;
    top: 0;

      background-image: url('@/assets/nvtou.png');
      // background: cover;
      background-size: cover;

  }
  .updown{
    width: 48.2vh;
    height: 26vh;
    background-color: #fff;
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-24.1vh);
    // position: relative;
    box-shadow: 0 0 10px 3px #ddd;
    .you {
      margin-top: 6vh;
      margin-left: 18.5vh;
      font-size: 12px;
    }
    .youke{
      margin-top: 6vh;
      margin-left: 15.8vh;
      font-size: 12px;
    }
    .login{
      width: 7.5vh;
      height: 3vh;
      background-color: #21b97a;
      border: 0px solid #000;
      border-radius: 1vh;
      margin-left: 14vh;
      margin-top: 1.8vh;
      font-size: 11px;
      color: #fff;
    }
    .outlogin{
      width: 9.5vh;
      height: 3vh;
      background-color: #21b97a;
      border: 0px solid #000;
      border-radius: 1vh;
      margin-left: 19.3vh;
      margin-top: 1.8vh;
      font-size: 11px;
      color: #fff;
    }
    .usermsg{
      font-size: 10px;
      margin-top: 2vh;
      margin-left: 18.5vh;
          color: #999;
    }
    .yuan{
      width: 7vh;
      height: 7vh;
      background-color: #fff;
      border-radius: 50%;
      position: absolute;
      left: 50%;
      top: -3vh;
      transform: translateX(-3.5vh);
      box-shadow: 0 2px 2px #bdbdbd;
      .avatar {
        width: 6vh;
        height: 6vh;
        // background-color: red;
        background-image: url('@/assets/avatar.png');
        background-size: 100%;
        margin-left: 0.6vh;
        margin-top: 0.5vh;
      }
    }
  }
}
</style>
